namespace ScrumSprintMonitor.ConfigEditor.Views.PresentationConfigurationEditorView
{
	#region #using Directives

	using System.Collections.ObjectModel;
	using System.Windows.Input;
	using System.Windows.Media;

	using ContinuousLinq.Reactive;

	using Infrastructure;
	using Infrastructure.Configuration;

	#endregion

	public interface IPresentationConfigurationEditorViewModel
	{
		Color[] Colors { get; }

		ObservableCollection<RemainingWorkStatusRatioUpperLimitEntry> RemainingWorkStatusRatioUpperLimits { get; }

		bool IsReadOnly { get; }

		ICommand OkCommand { get; }
		ICommand CancelCommand { get; }

		void Save();
	}

	public class RemainingWorkStatusRatioUpperLimitEntry : ReactiveObject
	{
		private IRemainingWorkStatusPresentationConfig statusPresentationConfig;

		static RemainingWorkStatusRatioUpperLimitEntry()
		{
			var dependsOn = Register<RemainingWorkStatusRatioUpperLimitEntry>();

			dependsOn.Call(me => me.OnPropertyChanged("IsLowerLimitReadOnly")).OnChanged(me => me.StatusPresentationConfig.LowerLimit);
			dependsOn.Call(me => me.OnPropertyChanged("IsUpperLimitReadOnly")).OnChanged(me => me.StatusPresentationConfig.UpperLimit);
		}

		public RemainingWorkStatusRatioUpperLimitEntry(IRemainingWorkStatusPresentationConfig statusPresentationConfig)
		{
			StatusPresentationConfig = statusPresentationConfig;
		}

		public IRemainingWorkStatusPresentationConfig StatusPresentationConfig
		{
			get { return this.statusPresentationConfig; }
			set
			{
				if (value != this.statusPresentationConfig)
				{
					this.statusPresentationConfig = value;

					OnPropertyChanged("StatusPresentationConfig");
				}
			}
		}

		public bool IsLowerLimitReadOnly
		{
			get { return this.statusPresentationConfig.Status == RemainingWorkStatus.NoWorkLeft; }
		}

		public bool IsUpperLimitReadOnly
		{
			get
			{
				return this.statusPresentationConfig.Status == RemainingWorkStatus.NoWorkLeft ||
				       this.statusPresentationConfig.Status == RemainingWorkStatus.SeverelyOverassigned;
			}
		}
	}
}